package com.example.demo.util;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;

public class OutputToInput {
	
	public static InputStream OutputToInput(final ByteArrayOutputStream out) throws IOException {
		PipedInputStream inputStream = new PipedInputStream();
		final PipedOutputStream outputStream = new PipedOutputStream(inputStream);
		new Thread(new Runnable() {
			
			@Override
			public void run() {
				try {
					out.writeTo(outputStream);
					outputStream.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}).start();
		
		return inputStream;
	}

}
